define(function (require, exports, module) {	
    var tpl1 = require("/mobile/tpl/redpacket/winebuyBack.tpl");
    var AjaxReturn = require('/plugins/extend/AjaxReturn');        
    AjaxReturn.ajaxPacket("/app/member/redpacket/availableWineCouponsJSON.html", "get", tpl1, "#winebuyBack");           
    $("#winebuyBack").delegate(".winebuybackli","click",function(e){
    	$(this).toggleClass("winebuybackli2");   	
    })   
    $("#winebuyBack").delegate(".wineVoucherToMoneyBtn","click",function(e){      		
    	var getCheckedV = $(".winebuybackli2");
		var len = getCheckedV.length;
		var voucherIds = [];    		
    		if(len==0){
    			layer.alert("请先选择酒券！");
    			return;
    		}
    		for(var i=0;i<len;i++){
    			if($(getCheckedV[i]).attr("data-val")=="0"){
    				layer.alert("您勾选的第"+(i+1)+"张酒券处于不可兑换现金状态！");
    				return;
    			}
    			voucherIds.push(getCheckedV[i].value);
    		}
    		layer.confirm('是否兑换选中的酒券?', {icon: 3, title:'提示'}, function(index){
    			$.ajax({
    				type: "post",
    		        url: "/app/member/redpacket/wineCouponsExchange.html",
    				traditional:true,
    				data:{'wineCouponsIds':voucherIds},
    	            success: function(data){
    	            	layer.alert(data.resMsg,{closeBtn:0},function(){
    	            		window.location.reload();
    	            	});
    	            }
    			});
    			layer.close(index);
    		});
    	});
});